import React, { useImperativeHandle } from "react";
import { Form, Input } from 'antd';
import type { IOuterCreateOrEditProps } from "@yaf/pro-ui";

const layout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 16 },
};

export const CreateOrEdit: IOuterCreateOrEditProps["CreateOrEditContent"] = React.forwardRef(({ values }, actionRef) => {
  const [form] = Form.useForm();
  useImperativeHandle(actionRef, () => ({
    getFormData: () => new Promise((resolve, reject) => {
      form.validateFields().then((data) => {
        resolve(data);
      }).catch(() => {
        reject(new Error("请检查参数"));
      });
    })
  }));

  return (
    <Form {...layout} initialValues={values} form={form}>
      <Form.Item
        label="名称"
        name="name"
        rules={[{ required: true, message: '请填写名称!' }]}
      >
        <Input />
      </Form.Item>
    </Form>
  )
});
